const { minify } = require('terser');

async function compressFile(inputPath, outputPath) {
  try {
    const result = await minify(inputPath);
    if (result.error) {
      console.error(result.error);
      return;
    }
    await fs.promises.writeFile(outputPath, result.code);
    console.log(`File compressed and minified successfully.`);
  } catch (error) {
    console.error(`Error compressing file: ${error}`);
  }
}

// 调用函数，传入输入文件路径和输出文件路径
compressFile('./main.js', './output.js');